"""
This file is test file, not used in this project.
"""
import os
import sys
import subprocess
import time

running_time_second = 10  # time (s)
ip_address = "192.168.0.2"
# ip_address = "172.16.117.102"

def main():
    style_name_random = "random"
    style_name_candy = "candy"
    
    work_dir = os.getcwd()
    print(work_dir)
    os.chdir(work_dir)

    for i in range(10):
        style_name = style_name_random
        cmd = "bash run_styletransferapp.sh %s video Channel-2 %s &" % (ip_address, style_name)
        ret = os.system(cmd)
        print("ret1:%d", ret)
        if ret == 0:
            print("end of sleep one")
        else:
            print("ret one failed")
        time.sleep(running_time_second)

        style_name = style_name_candy
        cmd = "bash run_styletransferapp.sh %s video Channel-2 %s &" % (ip_address, style_name)
        ret = os.system(cmd)
        print("ret2:%d", ret)
        if ret == 0:
            print("end of sleep two")
        else:
            print("ret two failed")
        time.sleep(running_time_second)

        print("=====%d=====" % (i))

## Depricated
def run_cmd_common(cmd, timeout=60, print_out=False, shell=True):
    try:
        out_bytes = subprocess.check_output(cmd, stderr=subprocess.PIPE, shell=shell, timeout=timeout)
    except subprocess.CalledProcessError as excp:
        fail_str = excp.stderr.decode('utf-8')
        print("output:%s" % (fail_str))
        return False, fail_str
    except Exception as excp:
        print("bash command execute failed.")
        return False, "bash command execute failed."

    return True, out_bytes.decode('utf-8')

if __name__ == "__main__":
    main()